// src/api/apiFunctions.js
import apiClient from './axios';

export const login = async (username, password) => {
  try {
    const response = await apiClient.post('/auth/login', { username, password });
    const { accessToken } = response.data;
    sessionStorage.setItem('accessToken', accessToken);
    return response.data;
  } catch (error) {
    if (error.response && error.response.data) {
      const { message } = error.response.data;
      console.error(`Error: ${message}`);
      throw new Error(message); // Throw only the message
    } else {
      console.error('Unknown error occurred');
      throw new Error('Failed to update order due to an unknown error');
    }
  }
};

export const logout = async () => {
  try {
    const response = await apiClient.post('/auth/logout',{});
 
    return response.data;
  } catch (error) {
      throw new Error('Failed to update order due to an unknown error');

  }
};


  export const getAdminMenus = async () => {
    try {
      const response = await apiClient.get('/menus');
      return response.data;
    } catch (error) {
      throw new Error('获取菜单失败');
    }
  };
  